var t = getApp();

Page({
    data: {
        language: "",
        supplier: "",
        member_id: "",
        balance: 0,
        service_type: 0,
        service_money: 0,
        withdrawType: {},
        withdrawToAlipay: 0,
        withdrawToWechat: 0,
        withdrawToManual: 0,
        poundage: "",
        eupshow: !1,
        hxShow: !1,
        info_form: {
            balance_money: ""
        },
        action: "",
        msg: "",
        notice: "",
        show2: !1,
        show3: !1,
        withList: [],
        checkObj: {},
        actual_amount: "",
        poundageHj: "",
        cost_money: "",
        poundage_name: ""
    },
    onLoad: function(t) {
        t.supplier && this.setData({
            supplier: t.supplier
        }), t.member_id && this.setData({
            member_id: t.member_id
        }), "supplier" === this.data.supplier ? this._getData2() : this._getData(), this.customizeIncome();
    },
    customizeIncome: function() {
        try {
            var t = wx.getStorageSync("mailLanguage");
            if (t) {
                var a = JSON.parse(t);
                this.setData({
                    poundage_name: a.income.poundage_name
                });
            }
        } catch (t) {}
    },
    onReady: function() {
        var t = wx.getStorageSync("langIndex");
        this.setData({
            language: t.en
        });
    },
    onShow: function() {},
    onHide: function() {},
    onUnload: function() {},
    onPullDownRefresh: function() {},
    onReachBottom: function() {},
    onShareAppMessage: function() {},
    _getData2: function() {
        var a = this, e = t.getNetAddresss("plugin.supplier.frontend.withdraw.index");
        e += "&member_id=" + this.data.member_id, t._getNetWork({
            url: e,
            success: function(t) {
                var e = t.data;
                1 == e.result ? a.setData({
                    balance: e.data.cost_money,
                    service_money: e.data.service_money,
                    service_type: e.data.service_type,
                    withdrawType: e.data.type
                }) : wx.showToast({
                    icon: "none",
                    title: e.msg,
                    duration: 1500
                });
            },
            fail: function(t) {
                console.log(t);
            }
        });
    },
    _getData: function() {
        var a = this, e = t.getNetAddresss("finance.balance-withdraw.page");
        t._getNetWork({
            url: e,
            success: function(t) {
                var e = t.data;
                1 == e.result ? a.setData({
                    balance: e.data.balance,
                    withdrawToAlipay: e.data.alipay,
                    withdrawToWechat: e.data.wechat,
                    withdrawToManual: e.data.manual,
                    poundage: e.data.poundage,
                    eupshow: e.data.eup_pay
                }) : wx.showToast({
                    icon: "none",
                    title: e.msg,
                    duration: 1500
                });
            },
            fail: function(t) {
                console.log(t);
            }
        });
    },
    balanceMoneyinp: function(t) {
        var a = t.detail.value;
        this.setData({
            "info_form.balance_money": a
        });
    },
    confirm: function(t) {
        var a = t.target.dataset.num;
        switch (this.setData({
            pay_type: a
        }), this.data.pay_type) {
          case "1":
          case "2":
            this.confirmPost(this.data.pay_type);
            break;

          case "3":
            this.manualVerify(this.data.pay_type);
            break;

          case "4":
            this.checkEup(this.data.pay_type);
            break;

          case "5":
            this.checkHx(this.data.pay_type);
        }
    },
    confirmPost: function(a) {
        var e = t.getNetAddresss("finance.balance-withdraw.withdraw");
        parseFloat(this.data.info_form.balance_money) > parseFloat(this.data.balance) ? wx.showToast({
            icon: "none",
            title: "提现金额不可大于您的余额",
            duration: 1500
        }) : null == this.data.info_form.balance_money || this.data.info_form.balance_money <= 0 || 0 == this.data.info_form.balance_money ? wx.showToast({
            icon: "none",
            title: "提现金额不可低于0",
            duration: 1500
        }) : (e += "&withdraw_type=" + a, e += "&withdraw_money=" + this.data.info_form.balance_money, 
        t._getNetWork({
            url: e,
            success: function(t) {
                var a = t.data;
                1 == a.result ? wx.showToast({
                    title: a.msg,
                    icon: "none",
                    duration: 1500,
                    success: function() {
                        setTimeout(function() {
                            wx.navigateBack({
                                delta: 1
                            });
                        }, 1500);
                    }
                }) : wx.showToast({
                    icon: "none",
                    title: a.msg,
                    duration: 1500
                });
            },
            fail: function(t) {
                console.log(t.msg);
            }
        }));
    },
    manualVerify: function(a) {
        var e = this, n = t.getNetAddresss("finance.balance-withdraw.is-can-submit");
        parseFloat(this.data.info_form.balance_money) > parseFloat(this.data.balance) ? wx.showToast({
            icon: "none",
            title: "提现金额不可大于您的余额",
            duration: 1500
        }) : null == this.data.info_form.balance_money || this.data.info_form.balance_money <= 0 || 0 == this.data.info_form.balance_money ? wx.showToast({
            icon: "none",
            title: "提现金额不可低于",
            duration: 1500
        }) : t._postNetWork({
            url: n,
            showToastIn: !1,
            data: {},
            success: function(t) {
                var n = t.data;
                1 == n.result ? response.data.status ? e.confirmPost(a) : e.setManualInfo(a, n.data.manual_type) : wx.showToast({
                    icon: "none",
                    title: n.msg,
                    duration: 1500
                });
            },
            fail: function(t) {}
        });
    },
    setManualInfo: function(t, a) {
        var e = "", n = "";
        switch (a) {
          case "bank":
            e = "请先填写银行卡信息", n = "/packageA/member/memberBank/memberBank";
            break;

          case "wechat":
            e = "请先填写微信信息", n = "/packageA/member/info/info";
            break;

          case "alipay":
            e = "请先填写支付宝信息", n = "/packageA/member/info/info";
        }
        wx.showModal({
            title: "提示",
            content: e,
            success: function(t) {
                t.confirm ? wx.navigateTo({
                    url: n
                }) : t.cancel && console.log("用户点击取消");
            }
        });
    },
    checkEup: function(a) {
        var e = this, n = t.getNetAddresss("plugin.eup-pay.api.account.pi-account");
        t._postNetWork({
            url: n,
            showToastIn: !1,
            data: {},
            success: function(t) {
                var n = t.data;
                if (1 == n.result) 1 == n.data.bool && e.confirmPost(a); else if (0 == n.result && 0 == n.data.bool) {
                    var o = n.msg;
                    wx.showModal({
                        title: "提示",
                        content: o,
                        success: function(t) {
                            t.confirm ? wx.navigateTo({
                                url: "/packageA/member/info/info"
                            }) : t.cancel && console.log("用户点击取消");
                        }
                    });
                }
            },
            fail: function(t) {
                wx.showToast({
                    icon: "none",
                    title: t,
                    duration: 1500
                });
            }
        });
    },
    submitbrank: function() {
        t._postNetWork({
            url: this.data.action,
            showToastIn: !1,
            data: {
                ipsRequest: this.data.msg
            },
            success: function(t) {
                wx.navigateBack({
                    delta: 1
                });
            },
            fail: function(t) {}
        });
    },
    suChange: function(t) {
        console.log(t, "事件啊啊"), this.setData({
            service_money: t.detail.value
        });
    },
    towithdrawalHj: function(a) {
        var e = this, n = a.target.dataset.index;
        if (this.setData({
            pay_type: n
        }), 5 != this.data.pay_type) this.towithdrawal(n); else {
            var o = t.getNetAddresss("plugin.converge_pay.frontend.controllers.converge-pay-bank-card.get-bank-card");
            t._getNetWork({
                url: o,
                success: function(t) {
                    var a = t.data;
                    if (1 == a.result) {
                        e.setData({
                            checkObj: a.data
                        });
                        var n = a.data.bankName + "(" + a.data.receiverAccountNoEnc.substring(a.data.receiverAccountNoEnc.length - 4) + ")";
                        return e.setData({
                            show2: !0,
                            "checkObj.bankName": n
                        }), e.getwithList(), void e.getCartWith();
                    }
                    return -1 == a.data.status && wx.navigateTo({
                        url: "/packageA/others/HJinfo/bankCardInformation/bankCardInformation"
                    }), void wx.showToast({
                        title: a.msg,
                        icon: "none"
                    });
                },
                fail: function(t) {
                    console.log(t.msg);
                }
            });
        }
    },
    getwithList: function() {
        var a = this, e = t.getNetAddresss("plugin.converge_pay.frontend.controllers.converge-pay-bank-card.get-bank-card-list");
        t._getNetWork({
            url: e,
            success: function(t) {
                var e = t.data;
                1 == e.result ? (0 == e.data.length && (wx.showToast({
                    title: "请先去添加银行卡",
                    icon: "none"
                }), wx.navigateTo({
                    url: "/packageA/others/HJinfo/bankCardInformation/bankCardInformation"
                })), e.data.map(function(t) {
                    t.check = !1, "" != t.receiverAccountNoEnc && null != t.receiverAccountNoEnc && (t.bankName += "(" + t.receiverAccountNoEnc.substring(t.receiverAccountNoEnc.length - 4) + ")");
                }), a.setData({
                    withList: e.data
                })) : (wx.showToast({
                    icon: "none",
                    title: e.msg,
                    duration: 1500
                }), setTimeout(function() {}, 2e3));
            },
            fail: function(t) {
                console.log(t);
            }
        });
    },
    getCartWith: function() {
        var a = this, e = t.getNetAddresss("plugin.supplier.frontend.withdraw.converge-withdraw");
        t._getNetWork({
            url: e,
            success: function(t) {
                var e = t.data;
                1 == e.result ? a.setData({
                    poundageHj: e.data.poundage,
                    actual_amount: e.data.actual_amount,
                    cost_money: e.data.cost_money
                }) : wx.showModal({
                    title: "提示",
                    content: e.msg
                });
            },
            fail: function(t) {
                console.log(t.msg);
            }
        });
    },
    getToTitle: function() {
        var a = this, e = t.getNetAddresss("plugin.converge_pay.frontend.controllers.converge-pay-bank-card.set-bank-card");
        t._postNetWork({
            url: e,
            data: {
                set: this.data.checkObj
            },
            success: function(t) {
                var e = t.data;
                1 == e.result ? a.towithdrawal(a.data.pay_type) : wx.showToast({
                    title: e.msg,
                    icon: "none",
                    duration: 1500
                });
            },
            fail: function(t) {
                console.log(t);
            }
        });
    },
    suppierGotiem: function() {
        console.log(this.data.checkObj, "选中的项"), this.getToTitle();
    },
    checkOut: function(t) {
        var a = t.target.dataset.item || t.currentTarget.dataset.item;
        a.check = !a.check, console.log(a, "当前对象");
        var e = this.data.withList;
        e.map(function(t) {
            t.id == a.id ? t.check = a.check : t.check = !1;
        }), console.log(e, "数组"), 1 == a.check && this.setData({
            show3: !1,
            show2: !0,
            checkObj: a,
            withList: e
        });
    },
    show1CloseBtn: function() {
        this.setData({
            show2: !1,
            show3: !1
        });
    },
    backGo: function() {
        this.setData({
            show2: !0,
            show3: !1
        });
    },
    backTap: function() {
        this.setData({
            show2: !1,
            show3: !1
        });
    },
    gotoList: function() {
        this.setData({
            show2: !1,
            show3: !0
        });
    },
    towithdrawal: function(a) {
        var e = this;
        if (null == this.data.balance || this.data.balance <= 0 || 0 == this.data.balance) wx.showToast({
            icon: "none",
            title: "提现金额不可低于0",
            duration: 1500
        }); else {
            var n = t.getNetAddresss("plugin.supplier.frontend.withdraw.withdraw");
            n += "&apply_type=" + this.data.pay_type, n += "&member_id=" + this.data.member_id, 
            t._getNetWork({
                url: n,
                success: function(t) {
                    var a = t.data;
                    1 == a.result ? (e.setData({
                        show2: !1
                    }), wx.showToast({
                        title: a.msg,
                        icon: "none",
                        duration: 1500,
                        success: function() {
                            setTimeout(function() {
                                wx.navigateBack({
                                    delta: 1
                                });
                            }, 1500);
                        }
                    })) : wx.showToast({
                        icon: "none",
                        title: a.msg,
                        duration: 1500
                    });
                },
                fail: function(t) {
                    console.log(t.msg);
                }
            });
        }
    }
});